package cn.zqy.demo2.day08.Recursion;

/**
 *     练习:   使用递归计算阶乘
 *             n的阶乘：n! = n * (n-1) *...* 3 * 2 * 1
 * */
public class Demo03FactorialRecursion {
    public static void main(String[] args) {
        int factorial = factorial(4);
        System.out.println(factorial);
    }

    /*
    * 递归结束的条件:
            获取到1的时候结束
      递归的目的:
            获取下一个被乘的数字(n-1)
    * */
    private static int factorial(int num) {
        if (num > 1) {
            return num * factorial(num - 1);
        } else if (num == 1) {
            return 1;
        } else {
            return 0;
        }
    }
}
